
import sqlalchemy


class AsyncBaseCrud:
    def __init__(self, engine):
        self.engine = engine
        self.Session = sqlalchemy.orm.sessionmaker(bind=self.engine)
        self.session = self.Session()

    async def create(self, model):
        """
        Create a new row in the table
        """
        self.session.add(model)
        self.session.commit()
        return model

    async def read(self, model_class, *args, **kwargs):
        """
        Read a row in the table
        """
        return self.session.query(model_class).filter_by(*args, **kwargs).all()

    async def update(self, model):
        """
        Update a row in the table
        """
        self.session.add(model)
        self.session.commit()
        return model

    async def delete(self, model):
        """
        Delete a row in the table
        """
        self.session.delete(model)
        self.session.commit()
